home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IFolderScrollMatrix.m < prev    next >
Text File  |  1993-01-12  |  8KB  |  242 lines

  1. /*$Copyright:
  2.  * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
  3.  * Institute for Supercomputing Research
  4.  * All rights reserved.
  5.  * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
  6.  *
  7.  * You may freely copy, distribute and reuse the code in this program under 
  8.  * following conditions.
  9.  * - to include this notice in the source code, if it is to be distributed 
  10.  *   with source code.
  11.  * - to add the file named "COPYING" within the code, which shall include 
  12.  *   GNU GENERAL PUBLIC LICENSE(*).
  13.  * - to display an acknowledgement in binary code as follows: "This product
  14.  *   includes software developed by Recruit Co.,Ltd., ISR."
  15.  * - to display a notice which shall state that the users may freely copy,
  16.  *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
  17.  *   LICENSE(*)
  18.  * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
  19.  *
  20.  *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  23.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  24.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  25. $*/
  26. /* Generated by Interface Builder */
  27.  
  28. #import "IFolderScrollMatrix.h"
  29. #import "IFolderCell.h"
  30. #import "IFolderScrollView.h"
  31. #import "TransparentWindow.h"
  32. #import "IDataGroupBrowser.h"
  33. #import "INXBrowserCellWithLinkedObject.h"
  34. #import "IUifNode.h"
  35. #import "InfoD.h"
  36. #import "ITreeNodeD.h"
  37. #import "errdebug.h"
  38. #import "data_types.h"
  39.  
  40. #import <appkit/NXImage.h>
  41. #import <appkit/ClipView.h>
  42. #import <appkit/ButtonCell.h>
  43. #import <appkit/Font.h>
  44. #import <string.h>
  45.  
  46. // this IfolderScrollMatrix class is asumed that it is set to a docment
  47. // view of ScrollView(or its subclass)
  48.  
  49. @implementation IFolderScrollMatrix
  50.  
  51. - initFrame:(NXRect *)frameRect
  52. {
  53.     NXSize    folderCellSize;
  54.     id        folderProto, titleFont;
  55.     
  56.     [super initFrame:frameRect];
  57.     
  58.     folderCellSize.width = frameRect->size.width;
  59.     folderCellSize.height = frameRect->size.height;
  60.     [self setCellSize:&folderCellSize];
  61.     [self setBackgroundGray:NX_LTGRAY];
  62.     [self setCellBackgroundGray:NX_LTGRAY];
  63.     [self setEnabled:YES];
  64.     [self notifyAncestorWhenFrameChanged:YES];
  65.     [self setMode:NX_TRACKMODE];    // mode is need
  66.     
  67.     folderProto = [[IFolderCell allocFromZone:[self zone]] 
  68.                         initIconCell:CLOSEDFOLDER];
  69.     [folderProto setBordered:NO];
  70.     [folderProto setIconPosition:NX_ICONABOVE];
  71.     [folderProto setTarget:self];
  72.     [folderProto setAction:@selector(selectNewsgroupInBrowser:)];
  73.     titleFont = [Font newFont:TITLEFONT size:TITLEFONTSIZE];
  74.     [folderProto setFont:titleFont];
  75.     [self setPrototype:folderProto];
  76.     
  77.     isPalette = YES;
  78.     return self;
  79. }
  80.  
  81. - newsgroupClicked:sender
  82. {
  83.     id        node;
  84.     id        iconImage;
  85.     id        folderCell;
  86.     const char    *groupname;
  87.     char    newsgroupName[512];
  88.     NXRect    contRect, docRect;
  89.     id        contView;
  90.     id        groupInfoD;
  91.     id        bcellList, bcell;
  92.     int        i, hiliCellCount;
  93.     id        lastColumnMatrix;
  94.  
  95.     DBG(1,fprintf(stderr,"-- newsgroup is clicked"));
  96.     // get selected column
  97.     lastColumnMatrix = [sender matrixInColumn:[sender selectedColumn]];
  98.     if ([[lastColumnMatrix selectedCell] isLeaf]==NO) {
  99.         [superview display];
  100.       return (self);
  101.     }
  102.     
  103.     // count hilighted cell in browser and setup newsgorupname for cell's title
  104.     bcellList = [lastColumnMatrix cellList];
  105.     hiliCellCount=0;
  106.     newsgroupName[0] = '\0';
  107.     for (i=0; bcell=[bcellList objectAt:i]; ++i) {
  108.     if ([bcell isHighlighted]) {
  109.         // node is a obj. of IUifNode, which is linked to 
  110.         // NXBrowserCellWithLinkedObject(subclass of NXBrowserCell)
  111.         node = [bcell node];
  112.         // get newsgroup name
  113.         groupInfoD = [[node linkedData] dataForKey:GROUPINFO];
  114.         groupname = [groupInfoD infoForKey:GROUPNAME];
  115.  
  116.         if (hiliCellCount != 0) {
  117.         // multiple cell is selected
  118.         // groupname will be separated by ','
  119.         strncat (newsgroupName, ",", (512-strlen(newsgroupName)-1));
  120.         }
  121.         // copy news group name 
  122.         strncat (newsgroupName, groupname, (512-strlen(newsgroupName)-1));
  123.         ++hiliCellCount;
  124.     }
  125.     }
  126.  
  127.     [window disableFlushWindow];
  128.  
  129.     // set up folderCell
  130.     [self _removeFolders];
  131.     [self addCol];
  132.  
  133.     [self sizeToCells];
  134.     [superview sizeTo:frame.size.width :frame.size.height];
  135.     
  136.     folderCell = [self cellAt:0 :1];    // root folder[0,0], news folder[0,1]
  137.  
  138.     // set up cell's image
  139.     if (hiliCellCount > 1) {
  140.     // cell in browser is multiple selected
  141.     iconImage = [NXImage findImageNamed:CLOSEDMULTIFOLDER];
  142.     } else {
  143.     iconImage = [NXImage findImageNamed:CLOSEDFOLDER];
  144.     }
  145.  
  146.     [folderCell setImage:iconImage];
  147.     [folderCell setTitle:newsgroupName];
  148.     [folderCell setLeaf:YES];
  149.  
  150.     // [superview superview]-> content view of scroll view
  151.     contView = [oScrollDocView superview];
  152.  
  153.     [contView getFrame:&contRect];    
  154.     [oScrollDocView getFrame:&docRect];
  155.  
  156.     docRect.size.width = frame.size.width;
  157.     // resize docView as same size as IFolderScrollMatrix
  158.     // ??this statement has side efect that docView will translate up a little
  159.     // (by 2 pixels) when you try to scroll in ScrollView??
  160.     [oScrollDocView setFrame:&docRect];
  161.     if (contRect.size.width < docRect.size.width) {
  162.     // document view width is larger than clip view, so move scroller
  163.     contRect.origin.x = docRect.size.width - contRect.size.width;
  164.     // ??move visible frame 2 pixels because of the side effect above??
  165. //    contRect.origin.y -= 2.0;
  166.     contRect.origin.y = 0.0;
  167.     [contView rawScroll:&(contRect.origin)];
  168.     [oScrollView reflectScroll:contView];
  169.     }
  170.  
  171.     [self display];
  172.     [window reenableFlushWindow];
  173.     return self;
  174. }
  175.  
  176. - registerCells
  177. {
  178.     int        i;
  179.     NXRect    iconRect, visibleRect;
  180.     NXPoint    iconCenter;
  181.     
  182.     // register allCells, it will get frame of cell rect and register it.
  183.     [super registerCells];
  184.     
  185.     // unregister unvisible cells
  186.     for (i = 0; i < numCols; ++i) {
  187.     // check if the center of icon is visible
  188.     [self getCellFrame:&iconRect at:0 :i];
  189.     [[self cellAt:0 :i] getIconRect:&iconRect];
  190.     iconCenter.x = iconRect.origin.x + iconRect.size.width/2;
  191.     iconCenter.y = iconRect.origin.y + iconRect.size.height/2;
  192.     
  193.     [[[superview superview] superview] getDocVisibleRect:&visibleRect];
  194.     DBG(10, fprintf(stderr,"-- iconCenter.x=%f\t y=%f\n", 
  195.                 iconCenter.x, iconCenter.y));
  196.     DBG(10, fprintf(stderr,"-- visibleRect.origin.x=%f\t y=%f\n    size.width=%f\t height=%f\n", visibleRect.origin.x,visibleRect.origin.y, visibleRect.size.width, visibleRect.size.height));
  197.  
  198.     if (NXPointInRect(&iconCenter, &visibleRect) == NO) {
  199.         [super unregisterCellAt:0 :i window:window];
  200.     }
  201.     }
  202.     return self;
  203. }
  204.  
  205. - setRootName:(char *)rootName
  206. {
  207.     id        rootCell;
  208.     
  209.     rootCell = [super setRootName:rootName];
  210.     [rootCell setLeaf:NO];
  211.     return self;
  212. }
  213.  
  214. - (void)_removeFolders
  215. {
  216.     // remove folder icons, leave only root icon(nextStation)
  217.     int        rowNum, colNum, i;
  218.  
  219.     // selected cell in newsgroup browser is directory
  220.     [self getNumRows:&rowNum numCols:&colNum];
  221.     // there are root folder and other folders, remove only folders
  222.     for (i=colNum; i > 1; --i) {
  223.     [self unregisterCellAt:0 :(i-1) window:window];
  224.     [self removeColAt:(i-1) andFree:YES];
  225.     [self sizeToCells];
  226.     [superview sizeTo:frame.size.width :frame.size.height];
  227.     }
  228. }
  229.  
  230. - selectNewsgroupInBrowser:sender
  231. {    
  232.     [super selectNewsgroupInBrowser:sender];
  233.     
  234.     if ([self selectedCol] == 0) {
  235.     [self _removeFolders];
  236.     [self display];
  237.     }
  238.     return (self);
  239. }
  240.  
  241. @end
  242.